# -*- shell-script -*-

# 33adapter_dt_sysfs - Device-tree + sysfs adapter code.

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2002, 2003, 2004, 2005

# Maintained by Martin Schwenke <martins@au.ibm.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
# $Id: 33adapter_dt_sysfs,v 1.1 2006/04/11 18:38:28 emunson Exp $

# NOTE: The sysfs devspec property was introduced in Linux 2.6.3, but
# let's assume that any system with sysfs and a device-tree will have
# devspec properties.  This will probably break one day, but checking
# for the existence of devspec properties isn't trivial.

[ -n "$source_device_tree" -a -n "$sysfs_dir" ] || return 0

######################################################################

# FIXME: scsi_debug, ide_cs

get_source_node_adapter ()
{
    # Sets: source_node
    source_node=""

    local node_type="$1"
    local bus_info="$2"
    local subtype="$3"

    local bus_type="${bus_info%/*}"
    local bus_addr="${bus_info#*/}"

    local d="${sysfs_dir}/bus/${bus_type}/devices/${bus_addr}/devspec"

    if [ -r "$d" ] ; then
	local suffix
        read suffix <"$d"

        [ -n "$suffix" ] && \
	    source_node="${source_device_tree}${suffix}"
    fi
}
